﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.JointJog.CUiKinJointJogOptionsForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.JointJog;

public class CUiKinJointJogOptionsForm : TxForm
{
  private static CUiKinJointJogOptionsFormData m_dialogData;
  private const string PRISMATIC_STEP_SIZE = "PrismaticStepSize";
  private const string REVOLUTE_STEP_SIZE = "RevoluteStepSize";
  private const string CUSTOM_SLIDER_SENSITIVITY_VALUE = "CustomSliderSensitivityValue";
  private const Decimal MAX_DECIMAL_MM = 7922815251426430000M;
  private const double PRISMATIC_STEP_SIZE_MIN_MM = 0.01;
  private const double PRISMATIC_STEP_SIZE_MAX_MM = 7.92281525142643E+18;
  private const double REVOLUTE_STEP_SIZE_MIN_RAD = 0.00017453292519943296;
  private const double REVOLUTE_STEP_SIZE_MAX_RAD = 12.566370614533705;
  private IContainer components;
  private TxButton m_buttonUp;
  private TxButton m_buttonDown;
  private GroupBox m_groupBoxColumnsManagement;
  private GroupBox m_groupBoxJointsOptions;
  private Label label1;
  private Label m_labelPrismaticStepSize;
  private Label m_labelRevoluteStepSize;
  private Label label7;
  private Button m_buttonCancel;
  private TxNumericEditBoxCtrl m_numericUpDownRevoluteStepSize;
  private TxNumericEditBoxCtrl m_numericUpDownPrismaticStepSize;
  private Button m_buttonOK;
  private Label label4;
  private Label label3;
  private Label label2;
  private TxTrackBar m_trackBarSliderSensitivity;
  private TxCheckedListBox txCheckedListBox1;

  public CUiKinJointJogOptionsForm()
  {
    this.InitializeComponent();
    this.m_buttonUp.SetImage(TxImageManager.GetImageByKey("ArrowUp"), new Size());
    this.m_buttonDown.SetImage(TxImageManager.GetImageByKey("ArrowDown"), new Size());
  }

  public CUiKinJointJogOptionsFormData DialogData => CUiKinJointJogOptionsForm.m_dialogData;

  public DialogResult ShowDialog(
    List<CUiKinJointJogForm.CUiKinJointJogColumnData> columns)
  {
    this.m_numericUpDownPrismaticStepSize.LowerBound = 0.01;
    this.m_numericUpDownRevoluteStepSize.LowerBound = 0.00017453292519943296;
    this.m_numericUpDownPrismaticStepSize.UpperBound = 7.92281525142643E+18;
    this.m_numericUpDownRevoluteStepSize.UpperBound = 4.0 * Math.PI;
    double? prismaticStepSizeValue;
    double? revoluteStepSizeValue;
    int? customSliderSensitivityValue;
    this.LoadOptionsData(out prismaticStepSizeValue, out revoluteStepSizeValue, out customSliderSensitivityValue);
    if (prismaticStepSizeValue.HasValue && revoluteStepSizeValue.HasValue && customSliderSensitivityValue.HasValue)
    {
      this.m_numericUpDownPrismaticStepSize.Value = prismaticStepSizeValue.Value;
      this.m_numericUpDownRevoluteStepSize.Value = revoluteStepSizeValue.Value;
      ((TrackBar) this.m_trackBarSliderSensitivity).Value = customSliderSensitivityValue.Value;
    }
    else
    {
      this.m_numericUpDownPrismaticStepSize.Value = 1.0;
      this.m_numericUpDownRevoluteStepSize.Value = Math.PI / 180.0;
    }
    foreach (CUiKinJointJogForm.CUiKinJointJogColumnData column in columns)
      ((CheckedListBox) this.txCheckedListBox1).Items.Add((object) new CUiKinJointJogForm.CUiKinJointJogColumnData(column), column.Visible);
    this.m_labelPrismaticStepSize.Text = TxApplication.Options.Units.LinearUnitName;
    this.m_labelRevoluteStepSize.Text = TxApplication.Options.Units.AngularUnitName;
    return ((Form) this).ShowDialog();
  }

  public void LoadOptionsData(
    out double? prismaticStepSizeValue,
    out double? revoluteStepSizeValue,
    out int? customSliderSensitivityValue)
  {
    object obj1;
    TxFormSettings.RestoreFormValue((Form) this, "PrismaticStepSize", ref obj1);
    object obj2;
    TxFormSettings.RestoreFormValue((Form) this, "RevoluteStepSize", ref obj2);
    object obj3;
    TxFormSettings.RestoreFormValue((Form) this, "CustomSliderSensitivityValue", ref obj3);
    if (obj1 != null && obj2 != null && obj3 != null)
    {
      prismaticStepSizeValue = new double?(Convert.ToDouble(obj1));
      double? nullable1 = prismaticStepSizeValue;
      double num1 = 0.01;
      if (nullable1.GetValueOrDefault() < num1 & nullable1.HasValue)
      {
        prismaticStepSizeValue = new double?(0.01);
      }
      else
      {
        double? nullable2 = prismaticStepSizeValue;
        double num2 = 7.92281525142643E+18;
        if (nullable2.GetValueOrDefault() > num2 & nullable2.HasValue)
          prismaticStepSizeValue = new double?(7.92281525142643E+18);
      }
      revoluteStepSizeValue = new double?(Convert.ToDouble(obj2) * Math.PI / 180.0);
      double? nullable3 = revoluteStepSizeValue;
      double num3 = 0.00017453292519943296;
      if (nullable3.GetValueOrDefault() < num3 & nullable3.HasValue)
      {
        revoluteStepSizeValue = new double?(0.00017453292519943296);
      }
      else
      {
        nullable3 = revoluteStepSizeValue;
        double num4 = 4.0 * Math.PI;
        if (nullable3.GetValueOrDefault() > num4 & nullable3.HasValue)
          revoluteStepSizeValue = new double?(4.0 * Math.PI);
      }
      customSliderSensitivityValue = new int?(Convert.ToInt32(obj3));
    }
    else
    {
      prismaticStepSizeValue = new double?();
      revoluteStepSizeValue = new double?();
      customSliderSensitivityValue = new int?();
    }
  }

  private void StoreOptionsData(
    double prismaticStepSize,
    double revoluteStepSize,
    Decimal customSliderSensitivityValue)
  {
    TxFormSettings.StoreFormValue((Form) this, "PrismaticStepSize", (object) prismaticStepSize);
    TxFormSettings.StoreFormValue((Form) this, "RevoluteStepSize", (object) (revoluteStepSize * 180.0 / Math.PI));
    TxFormSettings.StoreFormValue((Form) this, "CustomSliderSensitivityValue", (object) customSliderSensitivityValue);
  }

  private void SwitchCheckedListBoxItems(int index1, int index2)
  {
    CUiKinJointJogForm.CUiKinJointJogColumnData jointJogColumnData1 = ((CheckedListBox) this.txCheckedListBox1).Items[index1] as CUiKinJointJogForm.CUiKinJointJogColumnData;
    CUiKinJointJogForm.CUiKinJointJogColumnData jointJogColumnData2 = ((CheckedListBox) this.txCheckedListBox1).Items[index2] as CUiKinJointJogForm.CUiKinJointJogColumnData;
    ((CheckedListBox) this.txCheckedListBox1).Items[index1] = (object) jointJogColumnData2;
    ((CheckedListBox) this.txCheckedListBox1).SetItemChecked(index1, jointJogColumnData2.Visible);
    ((CheckedListBox) this.txCheckedListBox1).Items[index2] = (object) jointJogColumnData1;
    ((CheckedListBox) this.txCheckedListBox1).SetItemChecked(index2, jointJogColumnData1.Visible);
  }

  private void button1_Click(object sender, EventArgs e)
  {
    int selectedIndex = ((ListControl) this.txCheckedListBox1).SelectedIndex;
    if (selectedIndex <= 0)
      return;
    this.SwitchCheckedListBoxItems(selectedIndex, selectedIndex - 1);
    ((ListControl) this.txCheckedListBox1).SelectedIndex = selectedIndex - 1;
  }

  private void button2_Click(object sender, EventArgs e)
  {
    int selectedIndex = ((ListControl) this.txCheckedListBox1).SelectedIndex;
    if (selectedIndex <= -1 || selectedIndex >= ((CheckedListBox) this.txCheckedListBox1).Items.Count - 1)
      return;
    this.SwitchCheckedListBoxItems(selectedIndex, selectedIndex + 1);
    ((ListControl) this.txCheckedListBox1).SelectedIndex = selectedIndex + 1;
  }

  private void m_buttonOK_Click(object sender, EventArgs e)
  {
    List<CUiKinJointJogForm.CUiKinJointJogColumnData> columns = new List<CUiKinJointJogForm.CUiKinJointJogColumnData>();
    foreach (CUiKinJointJogForm.CUiKinJointJogColumnData jointJogColumnData in (ListBox.ObjectCollection) ((CheckedListBox) this.txCheckedListBox1).Items)
      columns.Add(jointJogColumnData);
    this.m_buttonOK.Focus();
    this.StoreOptionsData(this.m_numericUpDownPrismaticStepSize.Value, this.m_numericUpDownRevoluteStepSize.Value, (Decimal) ((TrackBar) this.m_trackBarSliderSensitivity).Value);
    int customSliderSensitivity = ((TrackBar) this.m_trackBarSliderSensitivity).Value;
    CUiKinJointJogOptionsForm.m_dialogData = new CUiKinJointJogOptionsFormData(columns, Convert.ToDouble(this.m_numericUpDownPrismaticStepSize.Value), Convert.ToDouble(this.m_numericUpDownRevoluteStepSize.Value), customSliderSensitivity);
    ((Form) this).Close();
  }

  private void m_buttonClose_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void txCheckedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
  {
    (((CheckedListBox) this.txCheckedListBox1).Items[e.Index] as CUiKinJointJogForm.CUiKinJointJogColumnData).Visible = e.NewValue == CheckState.Checked;
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiKinJointJogOptionsForm));
    this.m_buttonUp = new TxButton();
    this.m_buttonDown = new TxButton();
    this.m_groupBoxColumnsManagement = new GroupBox();
    this.txCheckedListBox1 = new TxCheckedListBox();
    this.m_groupBoxJointsOptions = new GroupBox();
    this.m_trackBarSliderSensitivity = new TxTrackBar();
    this.label4 = new Label();
    this.label3 = new Label();
    this.label2 = new Label();
    this.m_numericUpDownRevoluteStepSize = new TxNumericEditBoxCtrl();
    this.m_numericUpDownPrismaticStepSize = new TxNumericEditBoxCtrl();
    this.m_labelRevoluteStepSize = new Label();
    this.label7 = new Label();
    this.m_labelPrismaticStepSize = new Label();
    this.label1 = new Label();
    this.m_buttonCancel = new Button();
    this.m_buttonOK = new Button();
    this.m_groupBoxColumnsManagement.SuspendLayout();
    this.m_groupBoxJointsOptions.SuspendLayout();
    ((ISupportInitialize) this.m_trackBarSliderSensitivity).BeginInit();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_buttonUp, "m_buttonUp");
    ((Control) this.m_buttonUp).Name = "m_buttonUp";
    ((ButtonBase) this.m_buttonUp).UseVisualStyleBackColor = true;
    ((Control) this.m_buttonUp).Click += new EventHandler(this.button1_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonDown, "m_buttonDown");
    ((Control) this.m_buttonDown).Name = "m_buttonDown";
    ((ButtonBase) this.m_buttonDown).UseVisualStyleBackColor = true;
    ((Control) this.m_buttonDown).Click += new EventHandler(this.button2_Click);
    this.m_groupBoxColumnsManagement.Controls.Add((Control) this.txCheckedListBox1);
    this.m_groupBoxColumnsManagement.Controls.Add((Control) this.m_buttonDown);
    this.m_groupBoxColumnsManagement.Controls.Add((Control) this.m_buttonUp);
    componentResourceManager.ApplyResources((object) this.m_groupBoxColumnsManagement, "m_groupBoxColumnsManagement");
    this.m_groupBoxColumnsManagement.Name = "m_groupBoxColumnsManagement";
    this.m_groupBoxColumnsManagement.TabStop = false;
    ((ListControl) this.txCheckedListBox1).FormattingEnabled = true;
    componentResourceManager.ApplyResources((object) this.txCheckedListBox1, "txCheckedListBox1");
    ((Control) this.txCheckedListBox1).Name = "txCheckedListBox1";
    ((CheckedListBox) this.txCheckedListBox1).ItemCheck += new ItemCheckEventHandler(this.txCheckedListBox1_ItemCheck);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.m_trackBarSliderSensitivity);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.label4);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.label3);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.label2);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.m_numericUpDownRevoluteStepSize);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.m_numericUpDownPrismaticStepSize);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.m_labelRevoluteStepSize);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.label7);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.m_labelPrismaticStepSize);
    this.m_groupBoxJointsOptions.Controls.Add((Control) this.label1);
    componentResourceManager.ApplyResources((object) this.m_groupBoxJointsOptions, "m_groupBoxJointsOptions");
    this.m_groupBoxJointsOptions.Name = "m_groupBoxJointsOptions";
    this.m_groupBoxJointsOptions.TabStop = false;
    componentResourceManager.ApplyResources((object) this.m_trackBarSliderSensitivity, "m_trackBarSliderSensitivity");
    ((TrackBar) this.m_trackBarSliderSensitivity).Maximum = 61;
    ((TrackBar) this.m_trackBarSliderSensitivity).Minimum = 1;
    ((Control) this.m_trackBarSliderSensitivity).Name = "m_trackBarSliderSensitivity";
    ((TrackBar) this.m_trackBarSliderSensitivity).TickFrequency = 5;
    ((TrackBar) this.m_trackBarSliderSensitivity).Value = 31 /*0x1F*/;
    componentResourceManager.ApplyResources((object) this.label4, "label4");
    this.label4.Name = "label4";
    componentResourceManager.ApplyResources((object) this.label3, "label3");
    this.label3.Name = "label3";
    componentResourceManager.ApplyResources((object) this.label2, "label2");
    this.label2.Name = "label2";
    this.m_numericUpDownRevoluteStepSize.BorderStyle = BorderStyle.Fixed3D;
    componentResourceManager.ApplyResources((object) this.m_numericUpDownRevoluteStepSize, "m_numericUpDownRevoluteStepSize");
    this.m_numericUpDownRevoluteStepSize.LowerBound = 0.01;
    ((Control) this.m_numericUpDownRevoluteStepSize).Name = "m_numericUpDownRevoluteStepSize";
    this.m_numericUpDownRevoluteStepSize.ReadOnly = false;
    this.m_numericUpDownRevoluteStepSize.StepSize = 1.0;
    this.m_numericUpDownRevoluteStepSize.TextAlign = HorizontalAlignment.Left;
    this.m_numericUpDownRevoluteStepSize.ThousandsSeparator = false;
    this.m_numericUpDownRevoluteStepSize.UpperBound = 359.99;
    this.m_numericUpDownRevoluteStepSize.UseDecimalPlacesFromOption = true;
    this.m_numericUpDownRevoluteStepSize.Value = 1.0;
    this.m_numericUpDownRevoluteStepSize.ValueType = (TxNumericEditValueType) 1;
    this.m_numericUpDownPrismaticStepSize.BorderStyle = BorderStyle.Fixed3D;
    componentResourceManager.ApplyResources((object) this.m_numericUpDownPrismaticStepSize, "m_numericUpDownPrismaticStepSize");
    this.m_numericUpDownPrismaticStepSize.LowerBound = 0.01;
    ((Control) this.m_numericUpDownPrismaticStepSize).Name = "m_numericUpDownPrismaticStepSize";
    this.m_numericUpDownPrismaticStepSize.ReadOnly = false;
    this.m_numericUpDownPrismaticStepSize.StepSize = 1.0;
    this.m_numericUpDownPrismaticStepSize.TextAlign = HorizontalAlignment.Left;
    this.m_numericUpDownPrismaticStepSize.ThousandsSeparator = false;
    this.m_numericUpDownPrismaticStepSize.UpperBound = 1000000.0;
    this.m_numericUpDownPrismaticStepSize.UseDecimalPlacesFromOption = true;
    this.m_numericUpDownPrismaticStepSize.Value = 1.0;
    this.m_numericUpDownPrismaticStepSize.ValueType = (TxNumericEditValueType) 0;
    componentResourceManager.ApplyResources((object) this.m_labelRevoluteStepSize, "m_labelRevoluteStepSize");
    this.m_labelRevoluteStepSize.Name = "m_labelRevoluteStepSize";
    componentResourceManager.ApplyResources((object) this.label7, "label7");
    this.label7.Name = "label7";
    componentResourceManager.ApplyResources((object) this.m_labelPrismaticStepSize, "m_labelPrismaticStepSize");
    this.m_labelPrismaticStepSize.Name = "m_labelPrismaticStepSize";
    componentResourceManager.ApplyResources((object) this.label1, "label1");
    this.label1.Name = "label1";
    this.m_buttonCancel.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.m_buttonCancel, "m_buttonCancel");
    this.m_buttonCancel.Name = "m_buttonCancel";
    this.m_buttonCancel.UseVisualStyleBackColor = true;
    this.m_buttonCancel.Click += new EventHandler(this.m_buttonClose_Click);
    this.m_buttonOK.DialogResult = DialogResult.OK;
    componentResourceManager.ApplyResources((object) this.m_buttonOK, "m_buttonOK");
    this.m_buttonOK.Name = "m_buttonOK";
    this.m_buttonOK.UseVisualStyleBackColor = true;
    this.m_buttonOK.Click += new EventHandler(this.m_buttonOK_Click);
    ((Form) this).AcceptButton = (IButtonControl) this.m_buttonOK;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.m_buttonCancel;
    ((Control) this).Controls.Add((Control) this.m_groupBoxJointsOptions);
    ((Control) this).Controls.Add((Control) this.m_buttonOK);
    ((Control) this).Controls.Add((Control) this.m_buttonCancel);
    ((Control) this).Controls.Add((Control) this.m_groupBoxColumnsManagement);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiKinJointJogOptionsForm);
    ((Form) this).ShowIcon = false;
    this.m_groupBoxColumnsManagement.ResumeLayout(false);
    this.m_groupBoxJointsOptions.ResumeLayout(false);
    this.m_groupBoxJointsOptions.PerformLayout();
    ((ISupportInitialize) this.m_trackBarSliderSensitivity).EndInit();
    ((Control) this).ResumeLayout(false);
  }
}
